"""
登录的传参和相应模型
"""
from typing import List, Optional

from pydantic import Field

from server.schemas.BaseSchema import BaseSchema


class UserLogin(BaseSchema):
    """
    用户登录传参模型
    """
    username: str = Field(..., min_length=3, max_length=100)
    password: str = Field(...)


class MemuResponse(BaseSchema):
    """
    返回菜单模型
    """
    name: str
    path: Optional[str] = None
    icon: Optional[str] = None
    order: Optional[int] = None  # 允许为None
    permission: Optional[str] = None  # 允许为None
    order: Optional[int]



class RoleResponse(BaseSchema):
    """
    返回角色的列表模型
    """
    id: Optional[str] = None  # 允许为None
    name: Optional[str] = None
    code: Optional[str] = None
    description: Optional[str] = None
    menu_list: List[MemuResponse] = []  # 默认空列表


class UserResponse(BaseSchema):
    id: str
    username: str
    real_name: Optional[str] = None
    phone: Optional[str] = None
    is_active: bool
    is_superuser: bool
    avatar: Optional[str] = None
    role_list: List[RoleResponse] = []


class LoginResponse(BaseSchema):
    """
    用户登录正常响应数据模型
    """
    data: UserResponse
    token: str
    code: int
    msg: str


class LoginUsernameOrPasswordError(BaseSchema):
    """
    登录时用户或密码输入错误数据模型
    """
    code: int = 1400
    msg: str = "用户名或密码输入不正确"


class LoginUsernameIsNotActive(BaseSchema):
    """
    用户未激活模型
    """
    code: int = 1401
    msg: str = "用户未激活，请联系管理员"


class LoginPasswordValidateError(BaseSchema):
    code: int = 1402
    msg: str = "密码长度大于8且必须为数值、大小写字母、特殊字符组合"


class SuperUserResponse(BaseSchema):
    id: str
    username: str
    phone: Optional[str]
    real_name: Optional[str]
    is_superuser: bool
    is_active: bool
    avatar: Optional[str]


class SuperuserLoginResponse(BaseSchema):
    data: SuperUserResponse
    token: str
    code: int
    msg: str